﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace FileTime
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            using (OpenFileDialog ofd = new OpenFileDialog())
            {
                ofd.Multiselect = true;
                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    string[] files = ofd.FileNames;
                    foreach (string fileName in files)
                    {
                        if (File.Exists(fileName))
                        {
                            File.SetCreationTime(fileName, dateTimePicker1.Value);
                            File.SetLastWriteTime(fileName, dateTimePicker2.Value);
                            File.SetLastAccessTime(fileName, dateTimePicker3.Value);
                        }
                    }

                    MessageBox.Show("修改完成!");
                }
            }
           

          

            
        }

        private void button2_Click(object sender, EventArgs e)
        {

            StringBuilder sb = new StringBuilder();

            sb.AppendLine(dateTimePicker1.Value.ToString("yyyy-MM-dd HH:mm:ss"));
            sb.AppendLine(dateTimePicker2.Value.ToString("yyyy-MM-dd HH:mm:ss"));
            sb.AppendLine(dateTimePicker3.Value.ToString("yyyy-MM-dd HH:mm:ss"));


            string cfgFile = Path.Combine(Application.StartupPath, "cfg.txt");

            File.WriteAllText(cfgFile, sb.ToString());



            MessageBox.Show("保存OK!");


        }

        private void Form1_Load(object sender, EventArgs e)
        {
            string cfgFile = Path.Combine(Application.StartupPath, "cfg.txt");
            if (File.Exists(cfgFile))
            {
                string[] lines = File.ReadAllLines(cfgFile);

                dateTimePicker1.Value = DateTime.Parse(lines[0]);
                dateTimePicker2.Value = DateTime.Parse(lines[1]);
                dateTimePicker3.Value = DateTime.Parse(lines[2]);
            }

        }




    }
}
